package com.trkj.usercenter.charts;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.widget.TextView;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.trkj.base.BaseBackFragmentActivity;
import com.trkj.taoruiyun.R;

/**
 * Created by LiZanhong on 2015/06/25.
 */
public class ChartActivity extends BaseBackFragmentActivity{
    public static final String ACTION = "com.trkj.usercenter.charts.ChartActivity";

    @ViewInject(R.id.viewpager)
    private ViewPager viewPager;

    @ViewInject(R.id.indicate)
    private TextView indicate;

    private String[] indicateArray = {
            "● ○ ○ ○ ○ ○ ○",
            "○ ● ○ ○ ○ ○ ○",
            "○ ○ ● ○ ○ ○ ○",
            "○ ○ ○ ● ○ ○ ○",
            "○ ○ ○ ○ ● ○ ○",
            "○ ○ ○ ○ ○ ● ○",
            "○ ○ ○ ○ ○ ○ ●"
    };

    private Fragment[] fragments = {
            new YearExamFragment(),
            new ScoreLevelFragment(),
            new ExamRateFragment(),
            new LoginWeekFragment(),
            new LoginMonthFragment(),
            new LoginYearFragment(),
            new DetpRankFragment()
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_charts);
        ViewUtils.inject(this);

        viewPager.setAdapter(new ChartAdapter(getSupportFragmentManager()));
        viewPager.setOnPageChangeListener(new IndicatePageChangeListener());
    }

    @Override
    public String getCustomerTitle() {
        return "数据图表";
    }

    class ChartAdapter extends FragmentStatePagerAdapter{
        public ChartAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return fragments[position];
        }

        @Override
        public int getCount() {
            return fragments.length;
        }

        @Override
        public int getItemPosition(Object object) {
            return POSITION_NONE;
        }
    }

    class IndicatePageChangeListener implements ViewPager.OnPageChangeListener{
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int position) {
            indicate.setText(indicateArray[position]);
        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    }
}
